package com.auxgroup.smarthome.qcloud.controller;

import com.auxgroup.smarthome.qcloud.Service.AliCloudService;
import com.auxgroup.smarthome.qcloud.bean.FileModel;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * Created by niuGuangzhe on 2017/8/2.
 */
@Api(value = "阿里云储存相关操作", tags = "阿里云")
@RestController
@RequestMapping("alicloud")
public class AliCloudController {
    @Autowired
    private AliCloudService aliCloudService;

    @ApiOperation(value = "上传图片文件", notes = "单个上传文件，上传成功返回文件路径")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uploadFile", value = "上传的文件", required = true, paramType = "form", dataType = "file"),
    })
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public ApiResponse<FileModel> uploadFile(@RequestParam("uploadFile") MultipartFile file) throws IOException {
        if (file == null)
            return ApiResponse.prompt("-100", "请选择文件");

        return aliCloudService.uploadImg(file);
    }


    @ApiOperation(value = "上传apk文件", notes = "单个上传文件，上传成功返回文件路径")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uploadFile", value = "上传的文件", required = true, paramType = "form", dataType = "file"),
    })
    @RequestMapping(value = "/uploadApk", method = RequestMethod.POST)
    public ApiResponse<FileModel> uploadApk(@RequestParam("uploadFile") MultipartFile file) throws IOException {
        if (file == null)
            return ApiResponse.prompt("-100", "请选择文件");

        return aliCloudService.uploadApk(file);
    }

}
